using System;
using System.Configuration;
using System.IO;
using System.Media;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;

namespace DZRemoteController.Rules
{
	class SayItRule : IRule
	{
		protected string entry;
		protected string initFileName;
		protected string fileName;

		public virtual bool IsActive
		{
			get { return true; }
			set { }
		}

		public string FileName
		{
			get { return initFileName; }
			set 
			{ 
				initFileName = value;
				fileName = value;
			}
		}

		public virtual void Init(RuleElement rule)
		{
			entry = rule.Entry;
			FileName = Application.StartupPath + @"\Sound\" +rule.FileName;
		}

		public string Entry
		{
			get { return entry; }
			set { entry = value; }
		}

		public virtual bool Validate(string document)
		{
			Match m = Regex.Match(document, entry);
			return m.Success;
		}

		public virtual void Perform()
		{
			if (IsActive && File.Exists(fileName))
			{
				SoundPlayer pl = new SoundPlayer(fileName);
				pl.PlaySync();
			}

		}
	}
}